package principal;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class PanelGeneral extends JPanel {

	private Calendar fecha = Calendar.getInstance();
	protected int dia = fecha.get(Calendar.DATE);
	protected int mes = fecha.get(Calendar.MONTH) + 1;
	protected int anio = fecha.get(Calendar.YEAR);
	protected JLabel lbltitulo;
	protected JPanel marco;
	public Image imagen;
	protected JLabel hora;
	//protected Thread hilo = new Thread(this);
	//protected Boolean sigue=true;
	
	// constructor
	public PanelGeneral(String cad) {
		setLayout(null);
				
		imagen=new ImageIcon("imagenes/fondo05.jpg").getImage();
		
		marco=new JPanel();
		marco.setLayout(null);
		marco.setBounds(4,4,490,590);
		marco.setOpaque(false);
		marco.setBorder(BorderFactory.createEtchedBorder(0));
		add(marco);
		
		hora = new JLabel();
		hora.setBounds(10, 570, 150, 20);
		hora.setVisible(true);
		add(hora);
		
		lbltitulo = new JLabel(new ImageIcon("" + cad));
		lbltitulo.setBounds(125, 15, 250, 50);
		add(lbltitulo);
		
		//hilo.start();
	}
	
	 public void paint(Graphics g) {
		      g.drawImage(imagen, 0, 0, getWidth(), getHeight(),
			                        this);
			        setOpaque(false);
		         super.paint(g);
	    }
	
		
	public void cambiar(String url) {
		lbltitulo.setIcon(new ImageIcon(url));
		update(getGraphics());
	}


	protected void validarEntero(JTextField a) {
		a.addKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char caracter = e.getKeyChar();
				if ((caracter < '0') || (caracter > '9'))
					e.consume();
			}// 021235467
		});
	}

	protected static void validarLetra(JTextField a) {
		a.addKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char caracter = e.getKeyChar();
				if (!((caracter < '0') || (caracter > '9'))
						|| caracter == KeyEvent.VK_MINUS)
					e.consume();
			}
		});
	}

	protected static void validarReal(JTextField a) {
		a.addKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char caracter = e.getKeyChar();
				if (((caracter < '0') || (caracter > '9'))
						&& (caracter != KeyEvent.VK_BACK_SPACE && caracter != KeyEvent.VK_PERIOD)) {
					e.consume();
				}
			}
		});
	}

	protected String diadeHoy() {
		return dia + "/" + mes + "/" + anio;
	}

	public boolean validarLleno(JTextField s) {
		boolean b = true;
		if (s.getText().trim().isEmpty())
			return false;
		else
			return b;

	}

	protected void prohibeCopy(JTextField x) {
		InputMap map2 = x.getInputMap(x.WHEN_FOCUSED);
		map2.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK), "null");
	}

	/*@Override
	public void run() {
		while (sigue){
			Date fecha = new Date();
			SimpleDateFormat f1 = new SimpleDateFormat("EEEEEEEE d, HH:mm:ss");
			String fechaActual = f1.format(fecha);
			hora.setText(fechaActual+"");
			try {
				Thread.sleep(100);
			} catch (InterruptedException e){
				e.printStackTrace();
			}
		}
	}*/
	
}
